<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>0803_回调refs执行次数问题</title>
</head>

<body>
  <div id="test1"></div>
  <!-- react核心库 -->
  <script type="text/javascript" src="../js/react.development.js"></script>
  <!-- 用于支持react操作DOM -->
  <script type="text/javascript" src="../js/react-dom.development.js"></script>
  <!-- 用于将jsx转为js -->
  <script type="text/javascript" src="../js/babel.min.js"></script>

  <script type="text/babel">

    // 1.创建组件
    class Person extends React.Component {
      // 对标签属性类型、必要性做限制
      state = {
        isHot: true
      }
      render() {
        return (
          <div>
            <h2>今天天气很{this.state.isHot?'炎热': '凉爽'}</h2>
            <button onClick={this.changeWeather}>切换天气</button><br/>
            {/*<input ref={(c) => {this.input1 = c;console.log('@', c);}} type="text" placeholder="点击按钮提示数据"/>*/}
            <input ref={this.saveInput} type="text" placeholder="点击按钮提示数据"/>
            <button onClick={this.showData}>点击显示数据</button><br/>
          </div>
        )
      }
      // 点击提示数据
      showData = () => {
        let {input1} = this
        alert(input1.value)
      }
      // 回调input ref
      saveInput = c => {
        this.Input1 = c
      }

      changeWeather = () => {
        let {isHot} = this.state
        this.setState({isHot: !isHot})
      }
    }

    // 2.渲染虚拟DOM到页面
    ReactDOM.render(<Person/>, document.getElementById('test1'))
    
  </script>
</body>

</html>